//
//  UILabel+Custom.m
//  HotelUser
//
//  Created by yangfan on 2018/8/9.
//  Copyright © 2018年 wuhangongyou. All rights reserved.
//

#import "UILabel+Custom.h"
#import <CoreText/CoreText.h>
#import "YJXWorkOutLabelHeight.h"

@implementation UILabel (Custom)

+ (UILabel *)labWithTitle:(NSString *)title boldFontSize:(CGFloat)fontsize textColor:(UIColor *)color{
    return  [[self alloc] labWithTitle:title font:[UIFont boldPingFangFontOfSize:fontsize] textColor:color];
    
}

+ (UILabel *)labWithfontSize:(CGFloat)fontsize textColor:(UIColor *)color{
    return [self labWithTitle:nil fontSize:fontsize textColor:color];
}

+ (UILabel *)labWithTitle:(NSString *)title fontSize:(CGFloat)fontsize textColor:(UIColor *)color{
    return [[self alloc] labWithTitle:title fontSize:fontsize textColor:color];
}

- (UILabel *)labWithTitle:(NSString *)title fontSize:(CGFloat)fontsize textColor:(UIColor *)color{
    return  [self labWithTitle:title font:[UIFont pingFangFontOfSize:fontsize] textColor:color];
}


- (UILabel *)labWithTitle:(NSString *)title font:(UIFont *)font textColor:(UIColor *)color{
    UILabel *lab = [[UILabel alloc]init];
    lab.font = font;
    lab.textColor = color;
    lab.text = title;
    lab.backgroundColor = [UIColor whiteColor];
    return lab;
}

- (CGSize)workOutSizeHeightWithString:(NSString*)string fontSize:(UIFont*)fontSize value:(NSValue*)value lineSpace:(CGFloat)space textSpace:(CGFloat)textSpace firstLineHeadIndent:(CGFloat)firstLineHeadIndent{
    self.numberOfLines = 0;
    
    NSMutableAttributedString *attributes = [[NSMutableAttributedString alloc] initWithString:string];
    
    //调整字间距(字符串)
    [attributes addAttribute:(__bridge NSString *)kCTKernAttributeName value:@(textSpace) range:NSMakeRange(0, [attributes length])];
    
    //字体调整
    [attributes addAttribute:NSFontAttributeName value:fontSize range:NSMakeRange(0, string.length)];
    
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    
    // 行间距
    paragraphStyle.lineSpacing = space;  // 行间距
    //首行文本缩进
    paragraphStyle.firstLineHeadIndent = firstLineHeadIndent;//首行缩进
    
    [attributes addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, string.length)];
    
    
    self.attributedText = attributes;
    
    return  [YJXWorkOutLabelHeight workOutSizeHeightWithString:string fontSize:fontSize value:value lineSpace:space textSpace:textSpace firstLineHeadIndent:firstLineHeadIndent];
    
}



@end
